<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>单位1理解讲解</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            padding: 15px;
            background: #f5f5f5;
            line-height: 1.5;
        }
        
        .container {
            max-width: 900px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border: 1px solid #ddd;
        }
        
        .title {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
            font-size: 24px;
            font-weight: bold;
        }
        
        .section {
            margin-bottom: 20px;
            border-bottom: 1px solid #eee;
            padding-bottom: 15px;
        }
        
        .section:last-child {
            border-bottom: none;
        }
        
        .section-title {
            font-size: 18px;
            font-weight: bold;
            color: #333;
            margin-bottom: 10px;
        }
        
        .explanation {
            font-size: 14px;
            color: #666;
            margin-bottom: 15px;
        }
        
        .visual-demo {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 50px;
            margin: 20px 0;
        }
        
        .demo-item {
            text-align: center;
        }
        
        .circle-demo svg {
            width: 120px;
            height: 120px;
        }
        
        .segment-demo {
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        
        .segment-container {
            width: 200px;
            height: 20px;
            position: relative;
            margin: 10px 0;
        }
        
        .segment-base {
            width: 100%;
            height: 2px;
            background: #333;
            position: absolute;
            top: 9px;
        }
        
        .segment-fill {
            height: 2px;
            background: #007bff;
            position: absolute;
            top: 9px;
            transition: width 0.3s ease;
        }
        
        .segment-markers {
            position: absolute;
            top: 0;
            width: 100%;
            height: 20px;
        }
        
        .marker {
            position: absolute;
            width: 1px;
            height: 20px;
            background: #333;
        }
        
        .demo-label {
            font-size: 14px;
            font-weight: bold;
            color: #333;
            margin-top: 8px;
        }
        
        .demo-description {
            font-size: 12px;
            color: #888;
            margin-top: 3px;
        }
        
        .interactive-section {
            background: #f8f8f8;
            padding: 15px;
            margin-top: 15px;
        }
        
        .slider-container {
            margin: 15px 0;
        }
        
        .slider-label {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 8px;
            font-size: 14px;
        }
        
        .slider {
            width: 100%;
            height: 4px;
            background: #ddd;
            outline: none;
            -webkit-appearance: none;
        }
        
        .slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 16px;
            height: 16px;
            background: #007bff;
            cursor: pointer;
        }
        
        .slider::-moz-range-thumb {
            width: 16px;
            height: 16px;
            background: #007bff;
            cursor: pointer;
            border: none;
        }
        
        .result-display {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin: 15px 0;
        }
        
        .result-item {
            text-align: center;
            padding: 8px 12px;
            background: white;
            border: 1px solid #ddd;
            min-width: 80px;
        }
        
        .result-label {
            font-size: 12px;
            color: #666;
        }
        
        .result-value {
            font-size: 16px;
            font-weight: bold;
            color: #333;
        }
        
        .description-box {
            background: #fff3cd;
            color: #856404;
            padding: 10px;
            margin: 10px 0;
            text-align: center;
            font-size: 13px;
        }
        
        .examples-section {
            background: #e8f5e8;
            padding: 15px;
            margin-top: 15px;
        }
        
        .example-item {
            margin: 8px 0;
            padding: 8px;
            background: white;
            border-left: 3px solid #28a745;
            font-size: 13px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="title">单位1理解讲解</h1>
        
        <div class="section">
            <div class="section-title">核心概念</div>
            <div class="explanation">
                单位1代表一个完整的整体。在工程中，无论是材料总量、项目进度、还是设备容量，
                都可以用单位1表示完整状态。分数如1/4表示将整体平均分成4份后取其中1份。
            </div>
        </div>

        <div class="section">
            <div class="section-title">视觉演示</div>
            <div class="visual-demo">
                <div class="demo-item">
                    <div class="circle-demo">
                        <svg viewBox="0 0 100 100">
                            <circle cx="50" cy="50" r="45" fill="none" stroke="#ddd" stroke-width="2"/>
                            <path id="sector" fill="#007bff" stroke="#007bff" stroke-width="1" opacity="0.7"/>
                            <circle cx="50" cy="50" r="1" fill="#333"/>
                        </svg>
                    </div>
                    <div class="demo-label" id="circleLabel">扇形：1/4</div>
                    <div class="demo-description">角度、进度</div>
                </div>
                
                <div class="demo-item">
                    <div class="segment-demo">
                        <div class="segment-container">
                            <div class="segment-base"></div>
                            <div class="segment-fill" id="segmentFill"></div>
                            <div class="segment-markers" id="segmentMarkers"></div>
                        </div>
                    </div>
                    <div class="demo-label" id="segmentLabel">线段：1/4</div>
                    <div class="demo-description">长度、距离</div>
                </div>
            </div>
        </div>

        <div class="interactive-section">
            <div class="section-title">互动练习</div>
            <div class="slider-container">
                <div class="slider-label">
                    <span>分母（总份数）</span>
                    <span id="currentDenominator">4</span>
                </div>
                <input type="range" min="2" max="12" value="4" class="slider" id="fractionSlider">
                
                <div class="result-display">
                    <div class="result-item">
                        <div class="result-label">分数</div>
                        <div class="result-value" id="fractionResult">1/4</div>
                    </div>
                    <div class="result-item">
                        <div class="result-label">百分比</div>
                        <div class="result-value" id="percentageResult">25%</div>
                    </div>
                    <div class="result-item">
                        <div class="result-label">小数</div>
                        <div class="result-value" id="decimalResult">0.25</div>
                    </div>
                </div>
                
                <div class="description-box" id="descriptionBox">
                    整体平均分成4份，取其中1份
                </div>
            </div>
        </div>
        
        <div class="examples-section">
            <div class="section-title">工程实例</div>
            <div class="example-item">
                <strong>建筑：</strong>楼房总高度为单位1，第一层高度占1/4
            </div>
            <div class="example-item">
                <strong>机械：</strong>钢管总长度为单位1，切取1/3用于零件制造
            </div>
            <div class="example-item">
                <strong>电气：</strong>电池总容量为单位1，已使用3/4，剩余1/4
            </div>
            <div class="example-item">
                <strong>项目：</strong>工期总时间为单位1，已完成2/5，剩余3/5
            </div>
        </div>
    </div>

    <script>
        const slider = document.getElementById('fractionSlider');
        const sector = document.getElementById('sector');
        const segmentFill = document.getElementById('segmentFill');
        const segmentMarkers = document.getElementById('segmentMarkers');
        
        const fractionResult = document.getElementById('fractionResult');
        const percentageResult = document.getElementById('percentageResult');
        const decimalResult = document.getElementById('decimalResult');
        const currentDenominator = document.getElementById('currentDenominator');
        const circleLabel = document.getElementById('circleLabel');
        const segmentLabel = document.getElementById('segmentLabel');
        const descriptionBox = document.getElementById('descriptionBox');
        
        function createSectorPath(fraction) {
            const angle = fraction * 360;
            const radians = (angle - 90) * Math.PI / 180;
            const largeArc = angle > 180 ? 1 : 0;
            
            const x = 50 + 45 * Math.cos(radians);
            const y = 50 + 45 * Math.sin(radians);
            
            return `M 50,50 L 50,5 A 45,45 0 ${largeArc},1 ${x},${y} Z`;
        }
        
        function updateVisualization() {
            const denominator = parseInt(slider.value);
            const fraction = 1 / denominator;
            const percentage = Math.round(fraction * 100);
            const decimal = fraction.toFixed(3);
            
            // 更新数值显示
            fractionResult.textContent = `1/${denominator}`;
            percentageResult.textContent = `${percentage}%`;
            decimalResult.textContent = decimal;
            currentDenominator.textContent = denominator;
            
            // 更新标签
            circleLabel.textContent = `扇形：1/${denominator}`;
            segmentLabel.textContent = `线段：1/${denominator}`;
            descriptionBox.textContent = `整体平均分成${denominator}份，取其中1份`;
            
            // 更新扇形
            sector.setAttribute('d', createSectorPath(fraction));
            
            // 更新线段填充
            segmentFill.style.width = `${fraction * 100}%`;
            
            // 更新线段分割标记
            segmentMarkers.innerHTML = '';
            for (let i = 1; i < denominator; i++) {
                const marker = document.createElement('div');
                marker.className = 'marker';
                marker.style.left = `${(i / denominator) * 100}%`;
                segmentMarkers.appendChild(marker);
            }
        }
        
        slider.addEventListener('input', updateVisualization);
        
        // 初始化
        updateVisualization();
    </script>
</body>
</html>